package com.iot08.common.config.mongodb.query;

import org.springframework.data.mongodb.core.query.Update;
import org.springframework.lang.Nullable;

import java.util.Map;

/**
 * @version 1.0
 * @Description:
 * @time: 2020/12/17 16:49
 * @author: Rock
 */
public class UpdateVO extends Update {


    /**
     * 封装更新map类型字段方法
     *
     * @param key
     * @param value
     * @time: 2020/12/17 16:55
     * @author: Rock
     * @version 1.0
     */
    public Update setMap(String key, Map<String, Map<String, Object>> value) {
        if (value == null || value.size() == 0) {
            this.addMultiFieldOperation("$unset", key, 1);
        } else {
            this.addMultiFieldOperation("$set", key, value);
        }
        return this;
    }
}
